<template>
  <div>
    <!-- 面包屑 -->
    <bread :bread="$route.meta.bread" />
    <!-- 订单搜索表单区域 -->
    <el-form :inline="true">
      <el-form-item>
        <el-input
          placeholder="请输入订单号"
          v-model="query"
          style="width: 350px"
        >
          <el-button slot="append" icon="el-icon-search"></el-button>
        </el-input>
      </el-form-item>
    </el-form>
    <!-- 列表渲染区域 -->
    <el-table :data="orderList" style="width: 100%" border>
      <el-table-column label="#"
        ><template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template></el-table-column
      >
      <el-table-column prop="order_number" label="订单编号"> </el-table-column>
      <el-table-column prop="order_price" label="订单价格"> </el-table-column>
      <el-table-column prop="pay_status" label="是否付款">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.pay_status === '1'"
            >已付款</el-tag
          >
          <el-tag v-else type="danger">未付款</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="is_send" label="是否发货"> </el-table-column>
      <el-table-column prop="create_time" label="下单时间">
        <template slot-scope="scope">
          {{ scope.row.create_time | dateFormat }}
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template>
          <el-button
            type="primary"
            class="el-icon-edit"
            style="font-size='18px'"
          ></el-button>
          <el-button type="success" class="el-icon-location"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <div style="margin-top: 20px">
      <el-pagination
        @size-change="changeSize"
        @current-change="changePage"
        :current-page="pagenum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import bread from "../common/bread.vue";
export default {
  components: { bread },
  data() {
    return {
      // 模糊搜索关键字
      query: "",
      //当前页数
      pagenum: 1,
      //每页显示条数
      pagesize: 5,
      //   显示总条数
      total: 0,
      orderList: [],
    };
  },
  created() {},
  mounted() {
    this.getOrders();
  },
  methods: {
    getOrders() {
      this.$axios
        .get(
          `https://www.liulongbin.top:8888/api/private/v1/orders?query=${this.query}&pagenum=${this.pagenum}&pagesize=${this.pagesize}`
        )
        .then((res) => {
          console.log(res);
          this.orderList = res.data.goods;
          this.total = res.data.total;
        });
    },
    // 改变当前页使用的方法
    changePage(page) {
      this.pagenum = page;
      this.getOrders();
    },

    // 改变每页显示的数据个数的时候触发
    changeSize(size) {
      // 改变每页显示的条数
      this.pagesize = size;
      this.getOrders();
    },
  },
};
</script>

<style scoped>
</style>
